package com.jp.knowledge.my.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.jp.knowledge.R;
import com.jp.knowledge.comm.SlidingActivity;
import com.jp.knowledge.my.fragment.MyCommentsFragment;
import com.jp.knowledge.view.TabView;

import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/5/8.
 */

public class MyCommentsActivity extends SlidingActivity {

    @ViewInject(R.id.tab_view)
    private TabView tabView;
    @ViewInject(R.id.comments_viewpager)
    private ViewPager viewPager;

    private List<Fragment> fragments;

    @Override
    protected int getResourceId() {
        return R.layout.activity_my_comments;
    }

    @Override
    protected void init() {
        topName.setText("我的点评");
        rightIcon.setVisibility(View.GONE);
        leftIcon.setImageResource(R.mipmap.arrow_white_left);
        leftIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        fragments = new ArrayList<>();
        fragments.add(MyCommentsFragment.newInstance(application.getUserData(), 0));
        fragments.add(MyCommentsFragment.newInstance(application.getUserData(), 1));
        viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }
            @Override
            public int getCount() {
                return fragments.size();
            }
        });

        int tabIndex = getIntent().getIntExtra("tabIndex", 0);
        viewPager.setCurrentItem(tabIndex);

        tabView.setTabItems("我点评的", "我回复的");
        tabView.setupWithViewPager(viewPager);
    }
}
